#include "genotype.h"
#include "mouth.h"
#include "bodypart.h"
#include "constraint.h"

Genotype::Genotype()
{
	bodyArch = new BodyArch();
	brainzArch = new BrainzArch();

	count = 0;
	adamdist = 0;
}

void Genotype::registerBrainInputOutputs()
{

// BRAIN INPUTS
  unsigned int nextid = 1;

	// canprocreate
	brainzArch->registerInput( nextid++ );

  // being touched
  brainzArch->registerInput( nextid++ );

  // being eaten 
  brainzArch->registerInput( nextid++ );

	// energy state
	for ( unsigned int i=0; i < 10; i++ )
		brainzArch->registerInput( nextid++ );
  // age state
	for ( unsigned int i=0; i < 10; i++ )
		brainzArch->registerInput( nextid++ );
      
	// register constraint angles outputs as brain inputs
	for ( unsigned int i=0; i < bodyArch->archConstraints.size(); i++ )
    nextid = Constraint::registerInputs(brainzArch, nextid);

	// vision retina number of items
  // SJFIXME : now includes 'touching food' and 'touching critter' sensors.
	for ( unsigned int i=0; i < bodyArch->archBodyparts.size(); i++ )
   {
     if(bodyArch->archBodyparts[i].type == archBodypart::HEAD)
       nextid = Mouth::registerInputs(brainzArch, nextid);
     else
       nextid = Bodypart::registerInputs(brainzArch, nextid);
   }

  // BRAIN OUTPUTS

  nextid = 1;

	// procreate
	brainzArch->registerOutput( nextid++ );

	// register constraints's inputs as brain outputs
	for ( unsigned int i=0; i < bodyArch->archConstraints.size(); i++ )
	{
    nextid = Constraint::registerOutputs(brainzArch, nextid);
	}

  for ( unsigned int i=0; i < bodyArch->archBodyparts.size(); i++ )
  {
    if(bodyArch->archBodyparts[i].type == archBodypart::HEAD)
      nextid = Mouth::registerOutputs(brainzArch, nextid);
    else
      nextid = Bodypart::registerOutputs(brainzArch, nextid);
  }

}

string Genotype::saveGenotype()
{
	stringstream buf;
// 	buf << "color=" << color[0] << "," << color[1] << "," << color[2] << ";\n";
	buf << "adamdist=" << adamdist << ";\n";
// 	buf << "retinasize=" << retinasize << ";\n";

	string* bodyarch = bodyArch->getArch();
	string* brainarch = brainzArch->getArch();
	buf << *bodyarch;
	buf << *brainarch;
	//cout << *arch << endl;

	return buf.str();
}

Genotype::~Genotype()
{
	delete bodyArch;
	delete brainzArch;
}


